
require "Common/define"
require "Logic/Config"
require "Net/loginHandler"
require "Net/roleInfoHandler"
require "Net/itemHandler"
require "Net/chatHandler"
require "Net/friendHandler"
require "Net/shopHandler"
require "Net/towerHandler"
require "Net/playerHandler"
require "Net/equipHandler"
require "Net/partnerHandler"
require "Net/dungeonHandler"
require "Net/tacticsHandler"
require "Net/heroLinkHandler"
require "Net/emailHandler"
require "Net/costHandler"
require "Net/vipHandler"
require "Net/NoticeHandler"
require "Net/petHandler"
require "Net/BrokerHandler"
require "Net/ExpeditionHandler"
require "Net/unionMarketHandler"
require "Net/unionWishtHandler"
require "Net/unionHandler"
require "Net/unionWarHandler"
require "Net/unionWarPlusHandler"
require "Net/DarkStreetHandler"
require "Net/InvasionHandler"
require "Net/plunderHandler" -- 资源掠夺
require "Net/RealManWarHandler"
require "Net/skinHandler"
require "Net/runeHandler"
require "Net/DungeonRandomEventHandler"
require "Net/soloChaosTestHandler"
require "Net/newPlayerActiveHandler"
require "Net/longJourneyHellHandler" -- 旋云远征深渊
require "Net/HeroManorHandler" -- 家园系统

msgDispatcher = msgDispatcher or {}  
local main_type = Config.msg_main_type;
local this = msgDispatcher;

function msgDispatcher:Init()
	WebMsgMgr:AddEvent(this.DisPatchMsg);
end

--收到包解析协议main type丢到对应协议脚本
function  msgDispatcher.DisPatchMsg(p)
	local mainType = WebMsgMgr:getMainType(p);
	local subType = WebMsgMgr:getSubType(p);
	local switch = {  
	    [main_type.main_login] = function()  
	        loginHandler:receivePacket(p);
	    end, 
	    [main_type.main_roleList] = function()  
	        roleListHandler:receivePacket(p);
	    end, 
	    [main_type.main_roleInfo] = function()
	        roleInfoHandler:receivePacket(p);
	    end, 
	    [main_type.main_itemInfo] = function()  
	        itemHandler:receivePacket(p);
	    end, 
	    [main_type.main_npcInfo] = function()  
	        npcHandler:receivePacket(p);
	    end, 
	    [main_type.main_skillInfo] = function()  
	        skillHandler:receivePacket(p);
	    end, 
	    [main_type.main_mapInfo] = function()  
			mapHandler:receivePacket(p);
		end, 
		[main_type.main_fight] = function()  
			fightHandler:receivePacket(p);
		end,
		[main_type.main_itemForge] = function()  
			itemForgeHandler:receivePacket(p);
		end,
		[main_type.main_chat] = function()  
			chatHandler:receivePacket(p);
		end,
	    [main_type.main_task] = function()  
			taskHandler:receivePacket(p);
		end,  
		 [main_type.main_team] = function()  
			teamHandler:receivePacket(p);
		end,
		 [main_type.main_guild] = function()
			guildHandler:receivePacket(p);
		end,
		[main_type.main_friend] = function()
			friendHandler:receivePacket(p);
		end,
		[main_type.main_shop] = function()
			shopHandler:receivePacket(p);
		end,
		[main_type.main_reward] = function()
			rewardHandler:receivePacket(p);
		end,
        [main_type.main_consign] = function()
            consignHandler:receivePacket(p);
        end,
        [main_type.main_mercenary] = function()
            mercenaryHandler:receivePacket(p);
        end,
		[main_type.main_offline] = function()
			offlineHandler:receivePacket(p);
		end,
		[main_type.main_roundFight] = function()
            roundFightHandler:receivePacket(p);
        end,
        [main_type.main_arena] = function()
            arenaHandler:receivePacket(p);
        end,
		[main_type.main_active] = function()
            activeHandler:receivePacket(p);
        end,
        [main_type.main_charge] = function()
            chargeHandler:receivePacket(p);
        end,
	}  
	 --print("receive msg:"..getProtocol(mainType,subType))

	UIWaiting.HideWaiting(getProtocol(mainType,subType));
	local fSwitch = switch[mainType] --switch func

	if fSwitch then --key exists
	    local result = fSwitch() --do func
	else --key not found

	end
end
